home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / NetObjects Fusion 9 Standard / NOF9_Full_EN.exe / data1.cab / FSI / lib / nof / App.js next >
Encoding:
Text File  |  2005-11-16  |  13.4 KB  |  462 lines

  1. /****i* SOURCE_FILE/INFO
  2.   *
  3.   * NAME
  4.   *  App.js
  5.   *
  6.   * USAGE
  7.   *  Part of Netobjects JavaScript Library.
  8.   *
  9.   * COPYRIGHT
  10.   *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.   *  All Rights Reserved.
  12.   *
  13.   *  This is an unpublished work protected by Website Pros, Inc.
  14.   *  as a trade secret, and is not to be used or disclosed except as
  15.   *  expressly provided in a written license agreement executed by
  16.   *  you and Website Pros, Inc.
  17.   *
  18.   *      <copyright@websitepros.com>
  19.   *
  20.   * NOTES
  21.   *  JavaScript code.
  22.   *
  23.   *****/
  24.  
  25. //var IS = IS_getLibHandle();
  26. if (!IS.isModuleInitialized("IS.NOF.App"))
  27. {
  28.     /****h* NOF_JavaScript_Library/NOF.App
  29.     *
  30.     * NAME
  31.     *  NOF.App
  32.     *
  33.     * DESCRIPTION
  34.     *
  35.     *
  36.     ****/
  37.     
  38.   /**
  39.     * Constructor    
  40.     */  
  41.     function NOF_App( ) {
  42.         this.__proto__ = NOF_App.prototype;    
  43.         
  44.         this.libsPath = new Array();
  45.         
  46.         this.fsiApp        = null;
  47.         this.fsiApp2    = null;
  48.     }
  49.     {
  50.         var member = NOF_App.prototype;
  51.         //TODO:? determine the real file system path separator and file line break
  52.         member.PATH_SEPARATOR    = "/"; 
  53.         member.LINE_BREAK        = "\r\n";            
  54.         
  55.         /*
  56.             boolean runScript(String scriptPath, String jsExp)
  57.             string    getExeLocation()
  58.             string    getProfilesPath
  59.             string    getSerialNumber
  60.             string    getVersion
  61.             
  62.             string getTempDir 
  63.             string cleanTempDir
  64.             string copyToTempDir
  65.             string writeTempFile
  66.             
  67.             string    getUserSitesPath
  68.             
  69.             string getRecentSiteLocation(int pNumber)
  70.             setCurrentView(int pView) 
  71.             NOF.Site    newSite(String sitePath)
  72.             NOF.Site    openSite(String sitePath)
  73.             NOF.Site    getCurrentSite() 
  74.             NOF.UTIL.Locale    getLocale()
  75.             
  76.             setPassword (name, value, context) 
  77.             boolean hasPassword (name) 
  78.             
  79.             get/setVariable()    
  80.             
  81.             string getScriptsDirectory() //getScriptLibFolderPath()
  82.             DateFormat getDateFormat()
  83.             NumberFormat getNumberFormat ()
  84.             string getEncoding()
  85.             string getPathSeparator() // mac, windows 
  86.             string getLineBreak() // mac, windows
  87.         */
  88.         
  89.         var method = NOF_App.prototype;        
  90.         
  91.         method.super_release = method.release;
  92.         method.release = function () {
  93.             this.super_release();
  94.             this.fsiApp        = null;
  95.             this.fsiApp2    = null;            
  96.         }
  97.         
  98.         method.getFSIApp = function () {
  99.             if (this.fsiApp == null) {
  100.                 this.fsiApp = new ActiveXObject(NOF.ProgId.FSIApplication); 
  101.             }                
  102.             return this.fsiApp;
  103.         }        
  104.         
  105.         method.getFSIApp2 = function () {
  106.             if (this.fsiApp2 == null) {
  107.                 this.fsiApp2 = new ActiveXObject(NOF.ProgId.FSIApplication2); 
  108.             }                
  109.             return this.fsiApp2;
  110.         }
  111.         
  112.         /**
  113.         * Runs a script in Fusion.
  114.         * @param scriptPath - path to html file
  115.         * @param jsExp - expression to evaluate in the script.
  116.         * can be a function or another valid javascript expression
  117.         * @return false if the file is not found or the file does not contain the specified function (the expression can't be evaluated)
  118.         * It will also return false if the operation was canceled by calling cancelScript(true).
  119.         **/
  120.         method.runScript = function (/*String*/ scriptPath,/*String*/ jsExp) {
  121.             return this.getFSIApp().RunFSI(scriptPath, jsExp);
  122.         }
  123.         /**
  124.         * Communicates to Fusion that the current operation (started with runScript) is cancelled.
  125.         * (Fusion will check on return of the script the property set by this method to determine 
  126.         * whether the script was canceled or not)
  127.         * @param cancel - true if the script is canceled
  128.         **/
  129.         method.cancelScript = function (/*boolean*/ cancel) {
  130.             this.getFSIApp().Cancel = cancel;
  131.         }
  132.         /**
  133.         * Get the status of currently running script in Fusion,
  134.         * whether the script was canceled or not.
  135.         * @return true if the script was canceled
  136.         **/
  137.         /*boolean*/ method.isScriptCanceled = function () {
  138.             return this.getFSIApp().Cancel;
  139.         }
  140.         
  141.         /**
  142.         * Get the application's initial mode
  143.         * 
  144.         * @return 
  145.         **/
  146.         method.getInitMode    = function () { 
  147.             return this.getFSIApp().InitMode;
  148.         }        
  149.         /**
  150.         * Set the application's initial mode
  151.         * 
  152.         * @param initMode
  153.         **/
  154.         method.setInitMode    = function (/*int*/ initMode) { 
  155.             this.getFSIApp().InitMode = initMode;
  156.         }        
  157.         
  158.         /**
  159.             * Get the application's exe file path
  160.             * 
  161.             * @return the path to Fusion.exe
  162.             **/
  163.         method.getExeLocation    = function () { 
  164.             return this.getFSIApp().AppDirectory; //? + "Fusion.exe";
  165.         }        
  166.         
  167.         /**
  168.             * Get the application's System Directory file path
  169.             * 
  170.             * @return the path to NetObjects System folder
  171.             **/
  172.         method.getSystemDirectory    = function () { 
  173.             return this.getFSIApp().SystemDirectory;
  174.         }        
  175.         
  176.         /**
  177.             * Get the profiles base path
  178.             * 
  179.             * @return the path to profiles folder for current user
  180.             **/
  181.         method.getProfilesPath    = function () { 
  182.             var fsiConfigFile = new ActiveXObject(NOF.ProgId.FSIProfile);
  183.             var profilePath = fsiConfigFile.GetProfilePath();
  184.             fsiConfigFile = null;        
  185.             return profilePath;
  186.         }                
  187.         
  188.         /**
  189.             * Get the Fusion serial number
  190.             * 
  191.             * @return the string representing Fusion Serial Number
  192.             **/
  193.         method.getSerialNumber    = function () { 
  194.             return this.getFSIApp().SerialNumber;
  195.         }        
  196.         
  197.         /**
  198.             * Defines the version of the FSI API.
  199.             * 
  200.             * @return a string representing the version of the FSI API.
  201.             **/
  202.         method.getSDKVersionNumber    = function () { 
  203.             return this.getFSIApp().VersionNumber;
  204.         }        
  205.         
  206.         /**
  207.             * Defines the version of running Fusion
  208.             * 
  209.             * @return a string representing the version of the Fusion.
  210.             **/
  211.         method.getVersion = function () {         
  212.             var nofSettingsObj = new NOF.NOFSettings();
  213.             var fusionVersion = nofSettingsObj.get( "Version", NOF.NOFSettings.STRING_VALUE );
  214.             nofSettingsObj = null;
  215.             return fusionVersion;
  216.         }   
  217.         
  218.         /**
  219.             * sets the value of a new or existing system variable.
  220.             * 
  221.             * @param pName name of the variable
  222.             * @param pValue value of the variable
  223.             **/
  224.         method.setVariable = function (/*String*/ pName, /*String*/ pValue) { 
  225.             this.getFSIApp().SetSystemVar(pName, pValue);
  226.         }        
  227.         
  228.         /**
  229.             * Returns the value of a system variable. If the variable is not defined 
  230.             * the function will return an empty string.
  231.             * 
  232.             * @param pName name of the variable
  233.             * @return the value of the pName system variable
  234.             **/
  235.         method.getVariable = function (/*String*/ pName) { 
  236.             return this.getFSIApp().GetSystemVar(pName);
  237.         }                                    
  238.         
  239.         /**
  240.             * When defining a password you can define the context for which the password is valid,
  241.             * e.g.: SetPassword(passwordName, password, 'http://www.netobjects.com')
  242.             * @param passwordName defines a name for the password
  243.             * @param password defines the actual password. 
  244.             * @param context specifies the context for the password, which means that 
  245.             * the password can be inserted only in URLs that start with the specified context. 
  246.             * In functions accepting a URL the password can then be specified using the string:
  247.             * %pw_<passwordName>%
  248.             * If the password name is found and the context is valid the string will be replaced by 
  249.             * the actual password. Please note that the passwords are global, so it is important that 
  250.             * everyone using passwords is careful about the naming. For this reason each company 
  251.             * should include a company and maybe project specific identification in the name of each password.
  252.             * All passwords defined by NetObjects will contain the identification 'nof_'
  253.             * 
  254.             **/
  255.         method.setPassword = function (/*String*/ passwordName,/*String*/ password,/*String*/ context) { 
  256.             this.getFSIApp2().SetGlobalPassword(passwordName, password, context);
  257.         }    
  258.         
  259.         /**
  260.             * HasPassword verify if a password was defined or not. 
  261.             * Passwords are defined using the function SetPassword.
  262.             * @param passwordName
  263.             * @return a boolean specifying whether a password with the specified name is defined.
  264.             **/
  265.         method.hasPassword = function (/*String*/ passwordName) { 
  266.             return this.getFSIApp2().HasGlobalPassword(passwordName);
  267.         }            
  268.         
  269.         /**
  270.             * Get the location of a temporary directory available for Fusion scripts.
  271.             * If the directory does not already exist it will be created. 
  272.             * (You should use the temporary directory only within the execution of a single Fusion script).
  273.             * The directory and content may be deleted by any Fusion script. 
  274.             * 
  275.             * @return the path to the temporary folder in Fusion.
  276.             **/
  277.         method.getTempDirectory = function () { 
  278.             return this.getFSIApp().GetTempDir();
  279.         }
  280.         
  281.         /**
  282.             * Deletes the temporary directory (see getTempDirectory).
  283.             * 
  284.             **/
  285.         method.deleteTempDirectory = function () { 
  286.             this.getFSIApp().DeleteTempDir();
  287.         }
  288.         
  289.         /**
  290.             * Returns the path of a recent Fusion site file. 
  291.             * @param pNumber specifies a number of the recent file, where 0 is the most recent. 
  292.             * The function returns an empty string if there are no more recent files.
  293.             * 
  294.             **/
  295.         method.getRecentSiteLocation = function (/*int*/ pNumber) { 
  296.             return this.getFSIApp().GetRecentSite(pNumber);
  297.         }
  298.         
  299.         /**
  300.             * Specifies the view that should be opened.  
  301.             * 
  302.             * @param pView. The possible values are:
  303.             * 0 : site view, 1 : page view, 2 : style view, 3 : assets view, 4 : publish view, 5 : service view.
  304.             * 
  305.             **/
  306.         method.setCurrentView = function (/*int*/ pView) { 
  307.             this.getFSIApp().SetCurrentView(pView);
  308.         }    
  309.         
  310.         /**
  311.             * Creates a new blank site (and opens it). 
  312.             * If successful the previously open site (if any) will be closed.
  313.             *
  314.             * @return a NOF.Site object if the call succeeds
  315.             **/
  316.         method.newSite = function (/*String*/ sitePath) { 
  317.             var siteCreated = this.getFSIApp().NewBlankSite(sitePath);
  318.             var site = null;
  319.             if (siteCreated == true) {
  320.                 site = new NOF.Site(sitePath);
  321.             }
  322.             return site;
  323.         }    
  324.         
  325.         /**
  326.             * Opens the site specified by the sitePath. If successful the previously open site (if any) will be closed.
  327.             * @param sitePath path to the .nod file
  328.             * @param openPageView (optional - if defined, sitePath must be an integer - index of the site in the 'recent site list'),
  329.             * if true the site will be opened in Page view at the last opened page, otherwise the site will be opened in Site view
  330.             * @return a NOF.Site object if the call succeeds (or a boolean indicating the success of the operation)
  331.             **/
  332.         method.openSite = function (/*String*/ sitePath, /*boolean*/ openPageView) { 
  333.             if (arguments.length == 2 /* && openPageView != null*/) {
  334.                 return this.getFSIApp2().OpenRecentSite(/*int*/ sitePath, openPageView);
  335.             }
  336.             
  337.             var site = null;
  338.             var siteOpened = false;
  339.             
  340.             if (this.getFSIApp().IsSiteOpen(sitePath) == false) {
  341.                 siteOpened  = this.getFSIApp().OpenSite(sitePath);
  342.             } else {
  343.                 siteOpened = true;
  344.             }
  345.             if (siteOpened == true) {
  346.                 site = new NOF.Site(sitePath);
  347.             }                
  348.             return site;
  349.         }        
  350.         
  351.         /**
  352.             * Returns the currently open site. 
  353.             * 
  354.             * @return most recent opened site or null if there is no site open.
  355.             * 
  356.             **/
  357.         method.getCurrentSite = function () { 
  358.             var cSite = new NOF.Site(this.getRecentSiteLocation(0));
  359.             if (cSite.isOpen()) {
  360.                 return cSite;
  361.             } else {
  362.                 return null;
  363.             }
  364.         }
  365.         
  366.         /**
  367.         * Get the path to the scripts lib folder. 
  368.         * 
  369.         * @return the path to the scripts lib folder. 
  370.         **/            
  371.         method.getScriptsDirectory = function () {
  372.             return (this.getSystemDirectory() + this.PATH_SEPARATOR + "Fsi" + this.PATH_SEPARATOR + "lib");
  373.         }
  374.         
  375.         /**
  376.         * Add a new path to the scripts classpath
  377.         * @param pathsArray array of paths to Fusion folders
  378.         **/            
  379.         method.addLibsPath = function (/*String[]*/ pathsArray) {            
  380.             if ( pathsArray != null ) {
  381.                 var path;
  382.                 for (var i=0; i < pathsArray.length; i++) {
  383.                     path = pathsArray[i];
  384.                     if (this.libsPath.containsItem(path) < 0) {
  385.                         this.libsPath.add(path);
  386.                     }
  387.                 }
  388.             }
  389.         }
  390.         
  391.         /**
  392.         * Get classpath to scripts/modules
  393.         * @return an array of paths to Fusion folders
  394.         **/                    
  395.         method.getLibsPath = function () { 
  396.             var path = this.getSystemDirectory() + this.PATH_SEPARATOR + "Fsi";
  397.             if (this.libsPath.containsItem(path) < 0) {
  398.                 this.addLibsPath([path]);
  399.             }
  400.             return this.libsPath; 
  401.         }
  402.         method.setLibsPath = function (libsPath) { this.libsPath = libsPath; }  
  403.         
  404.         /**
  405.             * Get the file path separator. 
  406.             * @see NOF.IO.File
  407.             * @return the file path separator. as a string
  408.             **/                        
  409.         method.getPathSeparator = function () {
  410.             return this.PATH_SEPARATOR;
  411.         }
  412.         
  413.         /**
  414.             * Get the file line separator. 
  415.             * @see NOF.IO.File
  416.             * @return 
  417.             **/                                    
  418.         method.getLineBreak = function () {
  419.             return this.LINE_BREAK;
  420.         }
  421.         
  422.         /**
  423.             * Get Date format
  424.             * 
  425.             * @return 
  426.             **/            
  427.         method.getDateFormat = function () {
  428.             // TODO:      
  429.         }
  430.         
  431.         /**
  432.             * Get Number format
  433.             * 
  434.             * @return 
  435.             **/            
  436.         method.getNumberFormat = function () {
  437.             // TODO:      
  438.         }
  439.         
  440.         /**
  441.             * Get default locale
  442.             * 
  443.             * @return a NOF.UTIL.Locale instance corresponding to current Fusion's settings.
  444.             **/                        
  445.         /*NOF.UTIL.Locale*/ method.getDefaultLocale = function () {
  446.             var cfgObj = new NOF.NOFSettings();
  447.             var localeStr = cfgObj.get("locale", NOF.NOFSettings.STRING_VALUE);
  448.             cfgObj = null;
  449.             
  450.             if (localeStr == null || localeStr.length == 0) {
  451.                 localeStr = "enUS";
  452.             }
  453.             
  454.             var NOF_Language = localeStr.substring(0,2);
  455.             var NOF_Country  = (localeStr.length==4)?(localeStr.substring(2,4).toUpperCase()):null;
  456.             return new NOF.UTIL.Locale(NOF_Language, NOF_Country);
  457.         }
  458.     }    
  459.  
  460.     NOF.__proto__.App = new NOF_App();
  461.     
  462. }